package models;

import java.util.*;
import javax.persistence.*;

import play.Logger;
import play.db.ebean.*;
import play.data.format.*;
import play.data.validation.*;

import java.text.DateFormat;
import java.text.SimpleDateFormat;

/**
 * User entity managed by Ebean
 */
@Entity
@Table(name="UnavailableSeat")
public class UnavailableSeat extends Model {

	@Id
	public int id;

	public String seat_no;

	@ManyToOne
	public House house;

    // -- Queries
    public static Model.Finder<Long,UnavailableSeat> find = new Model.Finder(Long.class, UnavailableSeat.class);

	public UnavailableSeat(int house, String seat) {
		this.seat_no = seat;
		this.house = House.find.byId(house);
	}

	public static List<UnavailableSeat> findByHouse(int house) {
		return find.fetch("house").where().eq("house_id", house).findList();
	}

	public static boolean resetSeats(int house, String[] seats) {
		List<UnavailableSeat> useats = findByHouse(house);

		for(UnavailableSeat useat : useats){
			useat.delete();
		}

    	for(int i=0;i<seats.length;i++){
	    	new UnavailableSeat(house,seats[i]).save();
    	}

    	return true;
   	}

}

